import {observable, action} from "mobx";
import {getUrlParams} from "../../util";

export default class IndexStore {
    @observable selectedTab = "home";
    @observable hidden = false;

    @action  changeSelectTab = (tab, history) => {
        this.selectedTab = tab;
        if (tab === "projects") {
            let {tabs} = getUrlParams(history.location.search);
            if (tabs === undefined) {
                tabs = 0;
            }
            history.replace(`/index/${tab}?tabs=${tabs}`);
        } else if (tab === "task") {
            let {taskState, progress} = getUrlParams(history.location.search);
            if (taskState === undefined) {
                taskState = 2;
            }
        if (progress === undefined) {
            progress = 0;
        }
        history.replace(`/index/${tab}?taskState=${taskState}&progress=${progress}`);
    } else {
    history.replace("/index/" + tab);
}
    }
}
